{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第五次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer5文件夹下，**谢绝交到master下**\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在11月7日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  邓明慧\n",
    "+ 学号  0165200"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一、贫困户模型\n",
    "+ 创建一个类，包含贫困户的义务教育保障、住房安全、饮水安全、肉蛋奶豆的四个属性\n",
    "+ 包含一个是否贫困的预测，如果四个属性有两个以上没有保障（>2)则输出为贫困户\n",
    "+ 对贫困户，采取相应措施（输入参数）对其进行帮扶，使其脱贫\n",
    "+ 至少生成三个实例\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "贫困户，继续努力\n",
      "需要进行住房补贴\n",
      "需要污水处理\n",
      "需要进行营养补贴\n",
      "\n",
      "脱贫\n",
      "\n",
      "贫困户，继续努力\n",
      "需要提供培训\n",
      "需要污水处理\n",
      "需要进行营养补贴\n"
     ]
    }
   ],
   "source": [
    "class poor(object):\n",
    "    def __init__(self,x1,x2,x3,x4):\n",
    "        self.jiaoyu = x1\n",
    "        self.zhufang = x2\n",
    "        self.yinshui = x3\n",
    "        self.yinshi = x4\n",
    "        \n",
    "    def edu(self,jiaoyu):\n",
    "        if jiaoyu>1 :   ### 小学及小学以下为1，初中为2，高中为3，大学及大学以上为4\n",
    "            self.jiaoyu = 1\n",
    "        else :\n",
    "            self.jiaoyu = self.jiaoyu\n",
    "            \n",
    "    def house(self,zhufang):\n",
    "        if zhufang =='牢固' :\n",
    "            self.zhufang = 1\n",
    "        else :\n",
    "            self.zhufang = self.zhufang\n",
    "    \n",
    "    def water(self,yinshui):\n",
    "        if yinshui =='安全' or yinshui =='污水处理':\n",
    "            self.yinshui = 1\n",
    "        else:\n",
    "            self.yinshui = self.yinshui\n",
    "            \n",
    "    def health(self,yinshi):\n",
    "        if yinshi >1 or yinshi =='营养补贴' : #肉、蛋、奶、豆中，每周有一样则为1、两样为2，以此类推\n",
    "            self.yinshi = 1\n",
    "        else :\n",
    "            self.yinshi = self.yinshi\n",
    "            \n",
    "    def pinkunhu(self):\n",
    "        sum=0   \n",
    "        sum=self.zhufang+self.jiaoyu+self.yinshui+self.yinshi   \n",
    "        if sum<2:\n",
    "            print(\"\\n贫困户，继续努力\") \n",
    "            if self.zhufang==0:\n",
    "                print(\"需要进行住房补贴\")\n",
    "            if self.jiaoyu==0:\n",
    "                print(\"需要提供培训\")\n",
    "            if  self.yinshui==0:\n",
    "                print(\"需要污水处理\")\n",
    "            if  self.yinshui==0:\n",
    "                print(\"需要进行营养补贴\")\n",
    "        else :\n",
    "            print(\"\\n脱贫\")\n",
    "            \n",
    "mouhu1=poor(0,0,0,0)\n",
    "mouhu1.edu(jiaoyu=2)\n",
    "mouhu1.house(zhufang=0)\n",
    "mouhu1.water(yinshui=0)\n",
    "mouhu1.health(yinshi=1)\n",
    "mouhu1.pinkunhu()\n",
    "\n",
    "mouhu2=poor(0,0,0,0)\n",
    "mouhu2.edu(jiaoyu=2)\n",
    "mouhu2.house(zhufang='牢固')\n",
    "mouhu2.water(yinshui=0)\n",
    "mouhu2.health(yinshi=1)\n",
    "mouhu2.pinkunhu()\n",
    "\n",
    "mouhu3=poor(0,0,0,0)\n",
    "mouhu3.edu(jiaoyu=1)\n",
    "mouhu3.house(zhufang='牢固')\n",
    "mouhu3.water(yinshui=0)\n",
    "mouhu3.health(yinshi=1)\n",
    "mouhu3.pinkunhu()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二: 学生信息\n",
    "+ 创建一个类，包含姓名、分数、睡眠时间三个属性\n",
    "+ 包含一个胖瘦的预测，如果分数>90，且睡眠时间少于6小时，输出“BMI可能偏大”，否则输出“体重正常”\n",
    "+ 为使得标准（90分、6小时）可以调整，标准应设为输入的参数\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "xiaoke BMI可能偏大\n",
      "\n",
      "bingbing 体重正常\n",
      "\n",
      "xueying 体重正常\n"
     ]
    }
   ],
   "source": [
    "class student(object):\n",
    "    def __init__(self,name,score,sleep):\n",
    "        self.name=name\n",
    "        self.score=score\n",
    "        self.sleep=sleep\n",
    "    def zhengchang(self,st1,st2):\n",
    "        if (self.score>st1)&(self.sleep<st2):\n",
    "            print(\"\\n%s BMI可能偏大\"%self.name)\n",
    "        else:\n",
    "            print(\"\\n%s 体重正常\"%self.name)\n",
    "people1=student(\"xiaoke\",98,5)\n",
    "people1.zhengchang(90,6)\n",
    "\n",
    "people2=student(\"bingbing\",80,7)\n",
    "people2.zhengchang(85,6)\n",
    "\n",
    "people3=student(\"xueying\",110,7)\n",
    "people3.zhengchang(100,6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三：“跑步社”成员类\n",
    "+ 创建一个“跑步社”成员类，以学生信息类为父类\n",
    "+ 添加一个属性为跑步\n",
    "+ 如果跑步时间大于30分钟，如果之前预测为“BMI可能偏大”，则输出为“趋向正常”\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'体重正常'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class run_club(student):\n",
    "    def __init__(self,name,score,sleep,run):\n",
    "        super().__init__(name,score,sleep)\n",
    "        self.run=run\n",
    "    def zhengchang(self,st1,st2):\n",
    "        if (self.score>st1)&(self.sleep<st2):\n",
    "            if self.run>30:\n",
    "                return '趋向正常'          \n",
    "            else:\n",
    "                return 'BMI可能偏大'\n",
    "        else:\n",
    "            return '体重正常'\n",
    "\n",
    "people1=run_club(\"xiaoke\",98,5,40)\n",
    "people1.zhengchang(90,6)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'体重正常'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "people2=run_club(\"bingbing\",80,7,35)\n",
    "people2.zhengchang(85,6)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'体重正常'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "people3=run_club(\"xueying\",110,7,16)\n",
    "people3.zhengchang(100,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
